package android_design_mode.chapter07_strategy;

public class BusStrategy implements CalculateStrategy {
    @Override
    public int calculatePrice(int km) {

        if (km <= 10) {
            return 1;
        } else {
            // 超过10公里总距离
            int extraTotal = km - 10;
            // 超过5公里是5公里的倍数
            int extraFactor = extraTotal / 5;
            // 对5取余
            int fraction = extraTotal % 5;
            //
            int price = 1 + extraFactor;

            return fraction > 0 ? ++price : price;
        }

    }
}
